<template>
	<view class="container">
		<!-- 标题 -->
		<view class="page-title">添加活动 </view>
		<!-- 表单组件 -->
		<view class="form-wrapper">
			<u-form :model="uForm" ref="uForm" abelAlign="center" label-width="120rpx">
				<u-form-item labelWidth="65" label="选中产品" borderBottom @click="showtype = true">
					<u-input inputAlign="center" v-model="product_text" disabled disabledColor="#ffffff"
						placeholder="请选择所属产品" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="对外开放" borderBottom @click="showexhibitionl = true">
					<u-input inputAlign="center" v-model="exhibition_text" disabled disabledColor="#ffffff"
						placeholder="请选择是否对外开放" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="是否修改" borderBottom @click="showallow = true">
					<u-input inputAlign="center" v-model="allow_text" disabled disabledColor="#ffffff"
						placeholder="请选择是否可以修改" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="是否审核" borderBottom @click="showtexamine = true">
					<u-input inputAlign="center" v-model="examine_text" disabled disabledColor="#ffffff"
						placeholder="请选择是否可以审核" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="开始时间" bottom @click="showRegionPicker">
					<u-input inputAlign="center" v-model="uForm.start_time" disabled disabledColor="#ffffff"
						placeholder="请选择开始时间" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="截止时间" bottom @click="showEndFunction">
					<u-input inputAlign="center" v-model="uForm.end_time" disabled disabledColor="#ffffff"
						placeholder="请选择截止时间" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item labelWidth="65" label="价格">
					<u-input inputAlign="center" border="bottom" v-model="uForm.amount" placeholder="请输入价格" />
				</u-form-item>
				<u-form-item labelWidth="65" label="限制数量">
					<u-input inputAlign="center" border="bottom" v-model="uForm.quantity" placeholder="请输入限制人数" />
				</u-form-item>





				<u-form-item labelWidth="65" label="地址" prop="intro" borderBottom>
					<u-input placeholder="请输入省/市/区/详细地址" border="bottom" inputAlign="center"
						v-model="uForm.address"></u-input>
				</u-form-item>
			</u-form>

			<!-- <view style="display:flex;justify-content:space-between;margin-top:30px;padding-bottom:10px;">
				<view>
					设置为默认地址
				</view>
				<view>
					<u-switch asyncChange v-model="uForm.status_text" activeColor="#f56c6c"
						@change="ChangeCheck"></u-switch>
				</view>
			</view> -->
		</view>
		<u-action-sheet :actions="list" :title="'是否审核'" @select="showtexamineClick" @click="showexamine = true"
			:show="showtexamine" @close="showtexamineClickclose"></u-action-sheet>
		<u-action-sheet :actions="exhibitionlist" :title="'是否对外开放'" @select="showexhibitionlClick"
			@click="showexhibitionl = true" :show="showexhibitionl" @close="showexhibitionlclose"></u-action-sheet>
		<u-action-sheet :actions="allowlist" :title="'是否允许修改'" @select="showallowClick" @click="showallow = true"
			:show="showallow" @close="showallowclose"></u-action-sheet>

		<u-popup :show="showtype" @close="closeprotype" @open="openprotype">
			<view>
				<u-list height="560px">
					<u-list-item v-for="(item, index) in protypedata" :key="index">
						<view class="branktypename" @click="protypeSelect(item)">
							<u-cell :title="item.name">

							</u-cell>
						</view>
					</u-list-item>
				</u-list>
			</view>
		</u-popup>
		<u-datetime-picker :show="show" mode="datetime" closeOnClickOverlay @confirm="birthdayConfirm"
			@cancel="birthdayClose" @close="birthdayClose"></u-datetime-picker>
		<u-datetime-picker :show="showend" mode="datetime" closeOnClickOverlay @confirm="EndConfirm" @cancel="EndClose"
			@close="EndClose"></u-datetime-picker>
		<!-- 操作按钮 -->
		<view class="footer">
			<view class="btn-wrapper" @click="handleSubmit">
				<u-button type="primary" text="立即提交"></u-button>

			</view>
		</view>
		<u-toast ref="notice"></u-toast>

	</view>
</template>

<script>

import pickRegions from "../../components/pick-regions/pick-regions.vue";



export default {

	components: { pickRegions },


	onLoad(option) {
		this.getprolist()
	},


	data() {
		return {
			showexamine: false,
			showallow: false,
			showexhibitionl: false,
			showtexamine: false,
			allow_text: "允许",
			exhibition_text: "对外",
			product_text: "",
			examine_text: "无需",
			value1: Number(new Date()),
			list: [
				{
					name: "无需",
					examine: 0
				},
				{
					name: "需要",
					examine: 1

				},
			],
			allowlist: [
				{
					name: "不允许",
					allow: 0
				},
				{
					name: "允许",
					allow: 1

				},
			],
			exhibitionlist: [
				{
					name: "对内",
					exhibition: 0
				},
				{
					name: "对外",
					exhibition: 1

				},
			],
			show: false,
			showend: false,
			protypedata: [],
			showtype: false,

			// 必须要有默认值
			uForm: {
				end_time: "",
				start_time: "",

				address: "",
				exhibition: 1,
				examine: 0,
				allow: 1,
				quantity: "",
				amount: "",
				product_id: 0,
				user_id: 1

			},

		}
	},

	methods: {
		showexhibitionlClick(e) {
			this.exhibition_text = e.name
			this.exhibition = e.exhibition
			this.showexhibitionl = false

		},
		showexhibitionlclose(e) {

			this.showexhibitionl = false
		},
		showtexamineClick(e) {
			this.examine_text = e.name
			this.examine = e.examine
			this.showexamine = false

		},
		showtexamineClickclose(e) {

			this.showexamine = false
		},
		showallowClick(e) {
			this.showallow = false
			this.allow = e.allow
			this.allow_text = e.name
		},
		showallowclose() {
			this.showallow = false

		},

		closeprotype() { },
		openprotype() { },
		birthdayClose() {
			this.show = false
		},
		protypeSelect(e) {
			this.product_text = e.name,
				this.uForm.product_id = e.id;
				this.uForm.amount = e.price
			this.showtype = false
		},
		birthdayConfirm(e) {
			console.log(e)
			this.show = false
			this.uForm.start_time = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:ss')
		},

		EndClose() {
			this.showend = false
		},
		EndConfirm(e) {
			this.showend = false
			this.uForm.end_time = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:ss')

		},
		ChangeCheck() {

			this.uForm.status = !this.uForm.status
			this.uForm.status_text = !this.uForm.status_text




		},
		showEndFunction() {
			this.showend = true;
		},
		showRegionPicker() {
			this.show = true;
		},
		// 获取选择的地区
		handleGetRegion(region) {
			this.region = region;
			this.uForm.district = region[2].code
			this.uForm.province = region[0].code
			this.uForm.city = region[1].code

			this.uForm.region_text = this.region.map((item) => item.name).join("-");



		},

		// 表单提交
		async handleSubmit() {



			let result = await Addactivity(this.uForm)
			if (result.code) {
				this.$refs.notice.show({
					type: "success",
					message: result.msg,
					duration: 1500,
					complete: () => {
						uni.$u.route({
							url: "pageC/baoming/index"
						})
					}
				})


			}


		},
		async getprolist() {
      var result = await uni.$u.http.post("/product/get_signup", params);
			if (result.code) {
				this.protypedata = result.data
			}
		}



	}
}
</script>

<style>
page {
	background: #f7f8fa;
}
</style>
<style lang="scss" scoped>
.a {
	width: 340px !important;
}

.page-title {
	width: 94%;
	margin: 0 auto;
	padding-top: 40rpx;
	font-size: 28rpx;
	color: rgba(69, 90, 100, 0.6);
}

.form-wrapper {
	margin: 18rpx auto 20rpx -45px;
	padding: 0 106rpx;
	width: 85%;
	box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
	border-radius: 16rpx;
	background: #fff;
}

.branktypename {
	text-align: center;
}

// 底部操作栏
.footer {
	margin-top: 80rpx;

	.btn-wrapper {
		height: 100%;
		width: 80%;
		margin: 0 auto;

	}

	.btn-item {
		flex: 1;
		font-size: 28rpx;
		height: 86rpx;
		color: #fff;
		border-radius: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.btn-item-wechat {
		background: #0ba90b;
		margin-bottom: 26rpx;
	}

	.btn-item-main {
		background: linear-gradient(to right, #f9211c, #ff6335);
		color: #fff;

		// 禁用按钮
		&.disabled {
			opacity: 0.6;
		}
	}

}
</style>